
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <style>
        .txt{
            height: 30px;
            width: 80%;
            margin: 10px;
        }

    </style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="__STATIC__/js/json2.js"></script>
<script type="text/javascript" src="__STATIC__/js/client.js?d=2018-12-19_16:00:00"></script>
<script type="text/javascript" src="__STATIC__/js/jquery.min.js"></script>
<script type="text/javascript">
function SignDataAsPem(){
	//var passwd =
	EportClient.isInstalledTest(EportClient.cusSpcSignDataAsPEM,
		document.getElementById("txt1").value,"12345678",function(msg,msgJson){
		document.getElementById("txt2").value=JSON.stringify(msg);
		postSign(msg);
	});
}
</script>
	 
</head>

    <textarea rows="30" cols="60" id="txt1" placeholder="加签原文"></textarea>
    <textarea rows="30" cols="60" id="txt2" placeholder="加签结果"></textarea>
    <button onClick="SignDataAsPem()">手动加签</button>
    <button onClick="startCheck()">开始轮循</button>
    <button onClick="stopCheck()">停止轮循</button>

</div>
</body>
<script>
    var sessionId = '';

    function stopCheck() {
        clearInterval(iCount);
    }

    function startCheck() {
        iCount = setInterval(checkSignTodo, 5000)
    }

    var iCount = setInterval(checkSignTodo,5000);

	function checkSignTodo() {
		//console.log('yes');
        //查看后台是否有待加签数据
        $.ajax({
            type:"GET",
            url:"/cdkjt/jssign/getSignText",
            dataType:"json",
            success:function(data){
                if(data.code==1){
                    $("#txt2").val('');
                    sessionId = data.data.sessionId;
                    $("#txt1").val(data.data.signInit);
                    SignDataAsPem();            //调用加签
                    /*alert(signRs);
                    if(signRs.Result == true){
                       alert('yesok');
                    }*/
                }else{
                    console.log(data.msg);
                }

            },
            error:function(jqXHR){
                console.log("Error: "+jqXHR.status);
            }
        });
	}

	/*$(function () {
        $("#txt2").change(function () {
            alert($(this).val());
        });
    })
*/

	function postSign(signRs) {
        //var sign = $("#txt2").val();
        if(signRs.Result == true && sessionId != ''){
            var sign = signRs.Data[0];
            $.ajax({
                type:"POST",
                url:"/cdkjt/jssign/postSignText",
                data:{'sessionId':sessionId,'signval':sign},
                success:function(data){
                    console.log(data)
                },
                error:function(jqXHR){
                    console.log("Error: "+jqXHR.status);
                }
            })
        }

        if(sessionId != '' && sign != '')
        {
            //alert(sessionId);
            //alert(sign);
           /* $.ajax({
                type:"POST",
                url:"/cdkjt/jssign/postSignText",
                data:{'sessionId':sessionId,'signval':sign},
                success:function(data){
                    console.log(data)
                },
                error:function(jqXHR){
                    console.log("Error: "+jqXHR.status);
                }
            });*/

        }
    }

</script>
</html>